require 'ctx_rbm'
require 'add_comp_rbm'
require 'add_vecosem_dbm'
require 'dict'


torch.setdefaulttensortype('torch.DoubleTensor')

function main()
	-- load data
	local f = torch.DiskFile('data/toydata.dat', 'r')
	f:binary()
		local data 		= f:readObject():double()
		local cwdic 	= f:readObject() setmetatable(cwdic, Dict_mt)
		local wdic	 	= f:readObject() setmetatable(wdic, Dict_mt)
		local cwemb 	= f:readObject()
		local wemb 		= f:readObject()
		local sampler_storage = f:readObject()
	f:close()

	-- training
		print('training...')

		init_momentum = 0.9
		final_momentum = 0.9
		eps = 0.01
		weightcost = 0.001
		chainlen = 98
		nmarkovs = 99

		nepoch = 100
		batchsize = 100

		local comp_rbm = AddCompRBM:load_from_file('comp_model/4.model')
		local ctx_rbm = CtxRBM:load_from_file('ctx_model/2.model')
		local model = AddVeCoSemDBM:new(ctx_rbm, comp_rbm)
	
		print('training rbms...')
		model:train(data, nepoch, batchsize, init_momentum, final_momentum, 
					eps, weightcost, chainlen, nmarkovs, sampler_storage)
end

main()


